package com.jhws.business.car.controller;

import com.jhws.common.base.bo.JsonRespData;
import com.jhws.business.car.bo.CarLane;
import com.jhws.business.car.service.CarLaneService;
import com.jhws.business.car.service.MNSMessageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Controller
@RequestMapping("/car/carLane")
public class CarLaneController {
    @Resource
    private CarLaneService carLaneService;
    @Resource
    private MNSMessageService mnsMessageService;

    /**
     * 查询停车场通道
     *
     * @param parkId
     * @return
     */
    @RequestMapping("queryCarLane.x")
    @ResponseBody
    public JsonRespData queryCarLane(String parkId) {
        return new JsonRespData("", 1, carLaneService.queryCarLanes("where park_id='" + parkId + "'"));
    }

    /**
     * 创建通道队列
     *
     * @param carLaneId
     * @param isCreate
     * @return
     * @throws Exception
     */
    @RequestMapping("createQueue.x")
    @ResponseBody
    public JsonRespData createQueue(long carLaneId, boolean isCreate) throws Exception {
        CarLane carLane = carLaneService.queryCarLaneInfo(carLaneId);
        if (isCreate) {
            mnsMessageService.createQueue(carLane.getParkId() + "-" + carLane.getLaneCode(), 5, 60L);
            carLane.setMsgQueue(1);
        } else {
            mnsMessageService.deleteQueue(carLane.getParkId() + "-" + carLane.getLaneCode());
            carLane.setMsgQueue(0);
        }
        carLaneService.saveCarLane(carLane);
        return new JsonRespData("", 1, "");
    }
}
